package com.yxuan.springboot.controller;

import com.yxuan.springboot.service.ControlLineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import com.yxuan.springboot.model.ControlLine;
import com.yxuan.springboot.model.ControLineProvince;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * 
 * @author zchao
 *   ControlLine控制器
 * @date 2023-05-21 13:22:40
 */
@Controller
@Api(tags = "省控线")
@RequestMapping(value = "/controlline", method = {RequestMethod.POST,RequestMethod.GET})
@CacheConfig(cacheNames = "controlline")//缓存名，和管理器中配置的一致
public class ControlLineController extends BaseController<ControlLine>{

    @Autowired
    private ControlLineService controlLineService;

    /**
     *  查询省控线省份
     */
    @ApiOperation(value = "查询省控线省份", notes = "查询省控线省份")
    @RequestMapping("/loadProvinceByGroup")
    @ResponseBody
    @Cacheable(key = "'provincelist'",unless = "#result==null")//#result返回结果
    public List loadProvinceByGroup(){
        List<ControLineProvince> controLineProvince = controlLineService.fingProvinceByGroup();
        return controLineProvince;
    }

    /**
     *  根据省份查询年份
     */
    @ApiOperation(value = "根据省份查询年份", notes = "根据省份查询年份")
    @RequestMapping("/loadYearByProvince")
    @ResponseBody
    @Cacheable(key = "'provinceyear' + #province",unless = "#result==null")//#result返回结果
    public List loadYearByProvince(String province){
        List<ControlLine> controLine = controlLineService.findYearByProvince(province);
        ArrayList<String> arrayList = new ArrayList<>();
        for (ControlLine cs: controLine){
            arrayList.add(cs.getAdmissionYear());
            System.out.println(cs.getAdmissionYear());
        }
        return arrayList;
    }

}
